#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;

int n;
pair<int, int> a[N];

int main()
{
	cin >> n;
	for(int i = 1;i <= n;i ++) cin >> a[i].first >> a[i].second;
	sort(a + 1, a + 1 + n);
	int ans = 0, e = -1;
	for(int i = 1;i <= n;i ++)
	{
		if(a[i].first >= e) ans ++, e = a[i].second;
		else e = min(e, a[i].second);
	}
	cout << ans << endl;
	return 0;
}